//
//  RBAuthority.m
//  RBDemoProj
//
//  Created by Lan on 2018/12/19.
//  Copyright © 2018年 SummerTea. All rights reserved.
//

#import "RBAuthority.h"
#import <UIKit/UIKit.h>
#import <Photos/PHPhotoLibrary.h>
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>

@implementation RBAuthority

+ (void)checkCameraAuth
{
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied)
    {
        NSLog(@"相机访问受限");
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
    else if(status == AVAuthorizationStatusAuthorized)
    {
        NSLog(@"相机允许访问");
    }
    
}

+ (void)checkPhotoLibraryAuth
{
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied)
    {
        NSLog(@"相册访问受限");
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
    else if(status == PHAuthorizationStatusAuthorized)
    {
        NSLog(@"相册允许访问");
    }
}

+ (void)checkPhotoLibraryAddAuth
{
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied)
    {
        NSLog(@"相册访问受限");
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
    else if(status == PHAuthorizationStatusAuthorized)
    {
        NSLog(@"相册允许访问");
    }
}

@end
